<template>
	<view class="">
		<view class="card" v-if="list.length">
			<view class="integral_list">
				<view class="list" v-for="(item,index) in list" :key="index">
					<view class="list_l">
						<view class="tilte">
							{{item.type}}
						</view>
						<view class="date">
							{{item.create_time}}
						</view>
					</view>
					<view class='list_r' v-if="item.state == 1">
						+{{Math.floor(item.price) }}
					</view>
					<view class="list_r_jian" v-if="item.state == 2">
						-{{Math.floor(item.price) }}
					</view>
				</view>
			</view>
		</view>
		<uni-load-more :loadingType="loadingType" :contentText="contentText" ></uni-load-more>
		<sc-no v-if="!list.length" :noStatus="btnshowflag" @navtive="navtive" url="add_images/no_integraldetail.png" nofont="暂无积分明细" width="30%" noBtn="去登录"></sc-no>
		<shop-loading v-if="shopLoad"></shop-loading>
		<uni-login ref='login' @success="loginSuccess"></uni-login>
		<sc-home></sc-home>
	</view>
</template>

<script>
	import {
		financeIntagral
	} from '@/common/integral.js';
	import uniLoadMore from '@/components/uni-load-more.vue';
	import list from '@/mixins/list.js'
	import scNo from '@/components/sc-no/sc-no.vue';
	export default {
		components: {
			uniLoadMore,
			scNo
		},
		data() {
			return {
				Url: this.Imgurl,
				list: [],
				shopLoad: true,
				btnshowflag:false
			}
		},
		mixins: [list],
		methods: {
			navtive(){
				if(!uni.getStorageSync('token') && uni.getSystemInfoSync().version){
					this.login()
				}
			},
			login() {
				console.log("触发")
				if(uni.getSystemInfoSync().version){
				   this.$refs.login.show = true;	
				}
			},
			loginSuccess(){
				uni.setStorageSync('mineRefresh','false')
				this.getData()
			},
			getData() {
				this.shopLoad = true;
				console.log(this.page)
				let params = {
					account_type: '1',
					page: this.page
				}
				financeIntagral(params).then(res => {
					console.log(res)
					if (res.code == 1) {
						var order = res.msg.data
						this.btnshowflag = false
						if (order.length) {
							this.list = order
							this.page = res.msg.current_page
							this.last_page = res.msg.last_page
						}
						uni.hideLoading();
						uni.stopPullDownRefresh();
						this.loadingType = res.msg.last_page > 1 ? 0 : 2;
						this.shopLoad = false;
					}else if(res.code == 4){
						this.btnshowflag=true
						this.shopLoad = false;
						uni.hideNavigationBarLoading();
						uni.stopPullDownRefresh();
					} else {
						this.toast(res.msg)
						this.btnshowflag=false
						this.shopLoad = false;
						uni.hideNavigationBarLoading();
						uni.stopPullDownRefresh();
					}

				}).catch()
			},
			getmoreNews() {
				if (this.loadingType !== 0) { //loadingType!=0;直接返回
					return false;
				}
				this.loadingType = 1;
				uni.showLoading({
					title: '加载中'
				});
				if (this.page == this.last_page) {
					uni.hideLoading();
					uni.stopPullDownRefresh(); //得到数据后停止下拉刷新
				} else {
					this.page++;
					let params = {
						account_type: '1',
						page: this.page
					}
					var that = this
					financeIntagral(params).then(res => {
						var itemProduct = res.msg.data
						that.list = that.list.concat(itemProduct)
						this.loadingType = this.page == this.last_page ? 2 : 0
					}).catch()
					uni.hideLoading();

				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.card {
		box-sizing: border-box;
		width: 100%;
		margin: auto;
		margin-top: 20upx;
		background-color: #FFFFFF;

		.nohistory {
			background-color: #F9F9F9;
			overflow: hidden;
			text-align: center;

			image {
				width: 291upx;
				height: 201upx;
				display: block;
				margin: auto;
				margin-top: 200upx;
				margin-bottom: 30upx;
			}

			text {
				font-size: 28upx;
				color: #999999;
			}
		}

		.integral_list {
			width: 100%;
			height: 100%;
			padding: 0 25upx;
			box-sizing: border-box;

			.list {
				width: 100%;
				height: 136upx;
				border-bottom: 2upx solid #f8f8f8;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.list_l {
					.tilte {
						font-size: 28upx;
						color: #333333;
						line-height: 28upx;
					}

					.date {
						font-size: 24upx;
						color: #999999;
						line-height: 24upx;
						margin-top: 25upx;
					}
				}

				.list_r {
					font-size: 32upx;
					color: #6BCC03;
					font-weight: 700;
				}

				.list_r_jian {
					font-size: 32upx;
					color: #FF2842;
					font-weight: 700;
				}
			}

			.list:last-child {
				border-bottom: none;
			}
		}
	}
</style>
